package cn.iocoder.yudao.module.signature.controller.admin.developeraccountversion;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.signature.controller.admin.developeraccountversion.vo.*;
import cn.iocoder.yudao.module.signature.dal.dataobject.developeraccountversion.DeveloperAccountVersionDO;
import cn.iocoder.yudao.module.signature.service.developeraccountversion.DeveloperAccountVersionService;

@Tag(name = "管理后台 - 账号版本信息")
@RestController
@RequestMapping("/signature/developer-account-version")
@Validated
public class DeveloperAccountVersionController {

    @Resource
    private DeveloperAccountVersionService developerAccountVersionService;

    @PostMapping("/create")
    @Operation(summary = "创建账号版本信息")
    @PreAuthorize("@ss.hasPermission('signature:developer-account-version:create')")
    public CommonResult<Long> createDeveloperAccountVersion(@Valid @RequestBody DeveloperAccountVersionSaveReqVO createReqVO) {
        return success(developerAccountVersionService.createDeveloperAccountVersion(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新账号版本信息")
    @PreAuthorize("@ss.hasPermission('signature:developer-account-version:update')")
    public CommonResult<Boolean> updateDeveloperAccountVersion(@Valid @RequestBody DeveloperAccountVersionSaveReqVO updateReqVO) {
        developerAccountVersionService.updateDeveloperAccountVersion(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除账号版本信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('signature:developer-account-version:delete')")
    public CommonResult<Boolean> deleteDeveloperAccountVersion(@RequestParam("id") Long id) {
        developerAccountVersionService.deleteDeveloperAccountVersion(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得账号版本信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('signature:developer-account-version:query')")
    public CommonResult<DeveloperAccountVersionRespVO> getDeveloperAccountVersion(@RequestParam("id") Long id) {
        DeveloperAccountVersionDO developerAccountVersion = developerAccountVersionService.getDeveloperAccountVersion(id);
        return success(BeanUtils.toBean(developerAccountVersion, DeveloperAccountVersionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得账号版本信息分页")
    @PreAuthorize("@ss.hasPermission('signature:developer-account-version:query')")
    public CommonResult<PageResult<DeveloperAccountVersionRespVO>> getDeveloperAccountVersionPage(@Valid DeveloperAccountVersionPageReqVO pageReqVO) {
        PageResult<DeveloperAccountVersionDO> pageResult = developerAccountVersionService.getDeveloperAccountVersionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, DeveloperAccountVersionRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出账号版本信息 Excel")
    @PreAuthorize("@ss.hasPermission('signature:developer-account-version:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportDeveloperAccountVersionExcel(@Valid DeveloperAccountVersionPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<DeveloperAccountVersionDO> list = developerAccountVersionService.getDeveloperAccountVersionPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "账号版本信息.xls", "数据", DeveloperAccountVersionRespVO.class,
                        BeanUtils.toBean(list, DeveloperAccountVersionRespVO.class));
    }

}